//导入request.js请求工具
import request from '@/utils/request.js'

// 获取会议列表
export function getMeetingList(params) {
  const url = params.url || '/admins/meetings/getMeetings'
  delete params.url
  return request({
    url,
    method: 'get',
    params
  })
}

// 导出会议数据
export function exportMeetings(sortType, startDate, endDate, status, searchText) {
  const params = new URLSearchParams({
    sortType: sortType || 'asc',
    startDate: startDate || '',
    endDate: endDate || '',
    searchText: searchText || '',
    status: status || ''
  }).toString();

  return request({
    url: `/admins/meetings/exportEndedMeetings?${params}`,
    method: 'get',
    responseType: 'blob',
    timeout: 60000,
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    }
  });
}

// 获取会议详情
export function getMeetingDetail(mid) {
  return request({
    url: `/admins/meetings/getMeetingDetail/${mid}`,
    method: 'get'
  })
}

// 获取参会人列表
export function getParticipants(params) {
  return request({
    url: '/admins/meetings/getParticipants',
    method: 'get',
    params
  })
}

// 上传会议附件
export function uploadMeetingFile(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/admins/uploadCoverImg',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 新增会议
export function addMeeting(data) {
  return request({
    url: '/admins/meetings/addMeeting',
    method: 'post',
    data
  })
}

// 修改会议
export function updateMeeting(data) {
  return request({
    url: '/admins/meetings/updateMeeting',
    method: 'put',
    data
  })
}

// 删除会议
export function deleteMeeting(mid) {
  return request({
    url: `/admins/meetings/deleteMeeting/${mid}`,
    method: 'delete'
  })
}

// 获取会议统计数据
export function getMeetingStatistics() {
  return request({
    url: '/admins/meetings/statistics',
    method: 'get'
  })
}

// 获取会议趋势数据
export function getMeetingTrend(startDate, endDate) {
  const params = {}
  if (startDate) params.startDate = startDate
  if (endDate) params.endDate = endDate
  
  return request({
    url: '/admins/meetings/trend',
    method: 'get',
    params
  })
}

// 导出会议变化趋势数据
export function exportMeetingTrendData(startDate, endDate) {
  const params = new URLSearchParams()
  if (startDate) params.append('startDate', startDate)
  if (endDate) params.append('endDate', endDate)
  
  return request({
    url: `/admins/meetings/exportTrendData?${params.toString()}`,
    method: 'get',
    responseType: 'blob',
    timeout: 60000,
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    }
  })
}